#include "myshm.hpp"
#include <unistd.h>

int main()
{
    // 1. 打开共享内存
    key_t key = getKey();
    std::cout << "key:" << key << std::endl;
    int shmId = getShm(key);
    std::cout << "shmId:" << shmId << std::endl;

    // 2. 连接当前进程的PCB和打开的共享内存
    char* start = (char*)attachShm(shmId);
    printf("attach shm success, shmAddr:%p\n", start);

    // 3. 处理
    const char* msg = "Client(I) is communicating with server.";
    int cnt = 1;
    while(true)
    {
        snprintf(start, SHM_SIZE, "pid[%d]->%s-->number[%d]", getpid(), msg, cnt++);

        if(cnt == 5) break;

        sleep(1);
    }

    // 4. 删除连接
    deleteAttach(start);

    return 0;
}